"""
测试加解密工具
"""

from com.tools.Encode_Utils import Encoder
from com.tools.Decode_Utils import Decoder

def test_crypto():
    # 测试Base64
    print("测试Base64:")
    text = "Hello World"
    encoded = Encoder.base64_encode(text)
    print(f"原文: {text}")
    print(f"编码: {encoded}")
    decoded = Decoder.base64_decode(encoded)
    print(f"解码: {decoded}")
    print()

    # 测试MD5
    print("测试MD5:")
    md5_hash = Encoder.md5_encode(text)
    print(f"原文: {text}")
    print(f"MD5: {md5_hash}")
    print()

    # 测试SHA1
    print("测试SHA1:")
    sha1_hash = Encoder.sha1_encode(text)
    print(f"原文: {text}")
    print(f"SHA1: {sha1_hash}")
    print()

    # 测试SHA256
    print("测试SHA256:")
    sha256_hash = Encoder.sha256_encode(text)
    print(f"原文: {text}")
    print(f"SHA256: {sha256_hash}")
    print()

    # 测试3DES
    print("测试3DES:")
    key_3des = "mysecretpassword12345678"  # 24字节密钥
    encrypted_3des = Encoder.des3_encrypt(text, key_3des)
    print(f"原文: {text}")
    print(f"密钥: {key_3des}")
    print(f"加密: {encrypted_3des}")
    decrypted_3des = Decoder.des3_decrypt(encrypted_3des, key_3des)
    print(f"解密: {decrypted_3des}")
    print()

    # 测试AES
    print("测试AES:")
    key_aes = "mysecretpassword1234567890123456"  # 32字节密钥
    encrypted_aes = Encoder.aes_encrypt(text, key_aes)
    print(f"原文: {text}")
    print(f"密钥: {key_aes}")
    print(f"加密: {encrypted_aes}")
    decrypted_aes = Decoder.aes_decrypt(encrypted_aes, key_aes)
    print(f"解密: {decrypted_aes}")

if __name__ == "__main__":
    test_crypto()